home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / access / sql2va.zip / SQL2VAR.TXT < prev   
Text File  |  1993-07-29  |  5KB  |  127 lines

  1. SQL 2 Variable
  2. ==============
  3.  
  4. This little utility is used to format a long SQL statement
  5. so that it can be assigned to an Access Basic or Visual
  6. Basic variable in small chunks. Rather than assigning one 
  7. long string to the variable you can break it up into pieces.
  8. This makes the code much easier to read. 
  9.  
  10. For example, this program will reformat this:
  11.  
  12. TRANSFORM
  13.     Sum([Current Month Transactions].POUNDS) AS SumOfPOUNDS
  14. SELECT
  15.   PRODUCTS.COPRODUCT, 
  16.   [Current Month Transactions].LOCATION_CODE,
  17.   LOCATION_CODES.LOCATION_DESC,
  18.   [Current Month Transactions].PRODUCT_CODE,
  19.   [Current Month Transactions].PACKAGE_TYPE,
  20.   PRODUCTS.PRODUCT_NAME, 
  21.   PACKAGE_TYPE_CODES.PACKAGE_DESC
  22. FROM [Current Month Transactions], 
  23.      PRODUCTS,
  24.      PACKAGE_TYPE_CODES,
  25.      LOCATION_CODES,
  26.      [Current Month Transactions] 
  27. INNER JOIN PRODUCTS ON
  28.     [Current Month Transactions].PRODUCT_CODE = 
  29.     PRODUCTS.PRODUCT_CODE,
  30.     [Current Month Transactions]
  31. INNER JOIN PACKAGE_TYPE_CODES ON
  32.     [Current Month Transactions].PACKAGE_TYPE = 
  33.     PACKAGE_TYPE_CODES.PACKAGE_TYPE,
  34.     [Current Month Transactions] 
  35. INNER JOIN LOCATION_CODES ON
  36.     [Current Month Transactions].LOCATION_CODE = 
  37.     LOCATION_CODES.LOCATION_CODE
  38. GROUP BY PRODUCTS.COPRODUCT, 
  39.     [Current Month Transactions].LOCATION_CODE,
  40.     LOCATION_CODES.LOCATION_DESC, 
  41.     [Current Month Transactions].PRODUCT_CODE,
  42.     [Current Month Transactions].PACKAGE_TYPE,
  43.     PRODUCTS.PRODUCT_NAME, 
  44.     PACKAGE_TYPE_CODES.PACKAGE_DESC
  45. ORDER BY PRODUCTS.COPRODUCT, 
  46.     [Current Month Transactions].LOCATION_CODE,
  47.     LOCATION_CODES.LOCATION_DESC, 
  48.     [Current Month Transactions].PRODUCT_CODE, 
  49.     [Current Month Transactions].PACKAGE_TYPE
  50. PIVOT [Current Month Transactions].TRANSACTION_CODE 
  51.   In ("EI","S","TR","REC","BI","SL","SS","OG")
  52. WITH OWNERACCESS OPTION;
  53.  
  54. to:
  55.  
  56. sql = sql & "TRANSFORM "
  57. sql = sql & "Sum([Current Month Transactions].POUNDS) AS SumOfPOUNDS "
  58. sql = sql & "SELECT "
  59. sql = sql & "PRODUCTS.COPRODUCT, "
  60. sql = sql & "[Current Month Transactions].LOCATION_CODE, "
  61. sql = sql & "LOCATION_CODES.LOCATION_DESC, "
  62. sql = sql & "[Current Month Transactions].PRODUCT_CODE, "
  63. sql = sql & "[Current Month Transactions].PACKAGE_TYPE, "
  64. sql = sql & "PRODUCTS.PRODUCT_NAME, "
  65. sql = sql & "PACKAGE_TYPE_CODES.PACKAGE_DESC "
  66. sql = sql & "FROM [Current Month Transactions], "
  67. sql = sql & "PRODUCTS, "
  68. sql = sql & "PACKAGE_TYPE_CODES, "
  69. sql = sql & "LOCATION_CODES, "
  70. sql = sql & "[Current Month Transactions] "
  71. sql = sql & "INNER JOIN PRODUCTS ON "
  72. sql = sql & "[Current Month Transactions].PRODUCT_CODE = "
  73. sql = sql & "PRODUCTS.PRODUCT_CODE, "
  74. sql = sql & "[Current Month Transactions] "
  75. sql = sql & "INNER JOIN PACKAGE_TYPE_CODES ON "
  76. sql = sql & "[Current Month Transactions].PACKAGE_TYPE = "
  77. sql = sql & "PACKAGE_TYPE_CODES.PACKAGE_TYPE, "
  78. sql = sql & "[Current Month Transactions] "
  79. sql = sql & "INNER JOIN LOCATION_CODES ON "
  80. sql = sql & "[Current Month Transactions].LOCATION_CODE = "
  81. sql = sql & "LOCATION_CODES.LOCATION_CODE "
  82. sql = sql & "GROUP BY PRODUCTS.COPRODUCT, "
  83. sql = sql & "[Current Month Transactions].LOCATION_CODE, "
  84. sql = sql & "LOCATION_CODES.LOCATION_DESC, "
  85. sql = sql & "[Current Month Transactions].PRODUCT_CODE, "
  86. sql = sql & "[Current Month Transactions].PACKAGE_TYPE, "
  87. sql = sql & "PRODUCTS.PRODUCT_NAME, "
  88. sql = sql & "PACKAGE_TYPE_CODES.PACKAGE_DESC "
  89. sql = sql & "ORDER BY PRODUCTS.COPRODUCT, "
  90. sql = sql & "[Current Month Transactions].LOCATION_CODE, "
  91. sql = sql & "LOCATION_CODES.LOCATION_DESC, "
  92. sql = sql & "[Current Month Transactions].PRODUCT_CODE, "
  93. sql = sql & "[Current Month Transactions].PACKAGE_TYPE "
  94. sql = sql & "PIVOT [Current Month Transactions].TRANSACTION_CODE "
  95. sql = sql & "In ("
  96. sql = sql & chr$(34) & "EI"
  97. sql = sql & chr$(34) & ","
  98. sql = sql & chr$(34) & "S"
  99. sql = sql & chr$(34) & ","
  100. sql = sql & chr$(34) & "TR"
  101. sql = sql & chr$(34) & ","
  102. sql = sql & chr$(34) & "REC"
  103. sql = sql & chr$(34) & ","
  104. sql = sql & chr$(34) & "BI"
  105. sql = sql & chr$(34) & ","
  106. sql = sql & chr$(34) & "SL"
  107. sql = sql & chr$(34) & ","
  108. sql = sql & chr$(34) & "SS"
  109. sql = sql & chr$(34) & ","
  110. sql = sql & chr$(34) & "OG"
  111. sql = sql & chr$(34) & ") "
  112. sql = sql & "WITH OWNERACCESS OPTION; "
  113.  
  114. In some cases you might want to do a little cleanup of the
  115. generated code, but this utility should save you a little bit
  116. of typing if you often copy Access SQL statements into either
  117. Access Basic or Visual Basic code.
  118.  
  119. This utility is free. It requires the run-time file VBRUN300.DLL
  120. which is not included. You can find this file on the MSBASIC,
  121. WINFUN, or WINSHARE forums on Compuserve.
  122.  
  123. Jim Ferguson
  124. CIS: 71477,2345
  125.  
  126.  
  127.